<template>
  <div>
    <el-button type="primary" @click="showDialog">添加</el-button>
    <template>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="ID" type="index"></el-table-column>
        <el-table-column label="订单编号" width="220">{{
          orderId
        }}</el-table-column>
        <el-table-column prop="name" label="产品名称" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="price" label="金额" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="下单时间" show-overflow-tooltip
          >{{ datetime }}
        </el-table-column>
        <el-table-column prop="state" label="订单状态" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="address" label="操作" width="320">
          <el-button-group>
            <el-button type="success">订单</el-button>
            <el-button type="success">详情</el-button>
            <el-button type="danger">删除</el-button>
          </el-button-group>
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px">
        <el-button>全部删除</el-button>
      </div>
    </template>
    <!-- 分页栏 -->
    <el-pagination
      style="margin-top: 20px; text-align: center"
      :current-page="page"
      :total="total"
      :page-size="limit"
      :pager-count="7"
      :page-sizes="[3, 5, 10]"
      @current-change="page = 1"
      @size-change="handleSizeChange"
      layout="prev, pager, next, jumper,->,sizes,total"
    >
    </el-pagination>
    <!-- 添加框 -->
    <el-dialog :title="'添加订单'" :visible.sync="dialogFormVisible">
      <el-form style="width: 80%" :model="tmForm" :rules="rules" ref="ruleForm">
        <el-form-item label="产品名称" label-width="100px" prop="tmName">
          <el-input autocomplete="off" v-model="tmForm.tmName"></el-input>
        </el-form-item>
        <el-form-item label="订单状态" label-width="100px" prop="logoUrl">
          <el-input autocomplete="off" v-model="tmForm.tmState"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addOrUpdateTradeMark"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          name: "han",
          price: 3100,
          state: "已支付",
        },
      ],
      multipleSelection: [],
      orderId: "",
      datetime: "",
      page: 1,
      limit: 3,
      total: 1,
      dialogFormVisible: false,
      //收集品牌信息:对象身上的属性，不能瞎写，需要看文档的
      tmForm: {
        tmName: "",
        tmState: "",
      },
    };
  },
  created() {
    //自定义订单编号生成规则   由YYYYMMDD(年月日) + 时间戳的格式组成
    let currDate = new Date();
    let year = currDate.getFullYear();
    let month =
      currDate.getMonth() + 1 < 10
        ? "0" + (currDate.getMonth() + 1)
        : currDate.getMonth() + 1;
    let day =
      currDate.getDate() < 10 ? "0" + currDate.getDate() : currDate.getDate();

    let hours =
      currDate.getHours() < 10
        ? "0" + currDate.getHours()
        : currDate.getHours();

    let minutes =
      currDate.getMinutes() < 10
        ? "0" + currDate.getMinutes()
        : currDate.getMinutes();

    let time = hours + ":" + minutes;

    //获取年月日
    let date = year + month + day; //20190524
    let datetime = year + "-" + month + "-" + day + " " + time;

    //获取当时时间戳
    let timestamp = Date.parse(currDate); //155866554500

    //生成订单
    let orderId = date + timestamp; //20190524155866554500
    this.orderId = orderId;
    this.datetime = datetime;
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(limit) {
      //整理参数
      this.limit = limit;
    },
    showDialog() {
      //显示对话框
      this.dialogFormVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  margin: 5px;
}
</style>